package reflect;

import java.lang.reflect.Constructor;

/**
 * 分别使用无参构造器和有参构造器实例化Student
 */
public class Test {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Student");

        Object s1 = cls.newInstance();
        System.out.println(s1);

        //Student(String name, int age, char gender)
        Constructor c = cls.getConstructor(String.class,int.class,char.class);
        Object s2 = c.newInstance("张三", 18, '男');
        System.out.println(s2);
    }
}
